﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using ATM.DBlayer;
//using ATM.DBStublayer;


namespace ATM
{
    public class PayBillLogic
    {
        public int checkbill;
        public static float result;


        public static DataGridView grid = new DataGridView();

        AccountLogic account = new AccountLogic();
        PayBillDB billDB = new PayBillDB();
        AccountDB d = new AccountDB();
        

        public bool showbillcall(string company, string accountnum)
        {

            int x;
            if (!string.IsNullOrEmpty(company) && !string.IsNullOrEmpty(accountnum)  
                && !int.TryParse(company, out x)
                &&  int.TryParse(accountnum, out x)
                && int.Parse(accountnum) > 0)
            {
                PayBillDB.data = grid;

                billDB.showbillDB(company, accountnum);
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool paybillcall(string company, string accountnum)
        {

            int amount = Convert.ToInt32(billDB.num2); // the amount to pay
            int x;
            if (!string.IsNullOrEmpty(company) && !string.IsNullOrEmpty(accountnum)
                && !int.TryParse(company, out x)
                && int.TryParse(accountnum, out x)
                && int.Parse(accountnum) > 0)
            {
                billDB.paybillDB(company, accountnum);
                result = billDB.num - billDB.num2;
                if (result > 0 && billDB.num2!=0 && billDB.num2<=billDB.num )
                {
                    checkbill = 1;
                   // return true;

                    // record the transaction in the DB
                    d.RecordPaybill(accountnum, result,amount );                    

                }
                else
                {

                    checkbill = 0;
                    //return false;
                }
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool add_t_balnce(string AN)
        {
            int x;
            if (string.IsNullOrEmpty(AN) || !int.TryParse(AN,out x))
                return false;
            else
            {

                int new_result = Convert.ToInt32(result);
                account.balancechange(AN, new_result);
                return true;
            }
        }
        

    }
}
